// pages/about/index.js
const { BASEURL } = require('../../utils/baseurl')
const { helpMy, updMemberInfo } = require('../../utils/api')
const { fetch } = require('../../utils/fetch')

import { Base } from '../../utils/base.js';
var base = new Base();

Page({
  data: {
    // url: BASEURL + helpMy,
    headimg:'',
    nickname:'',
    birthday:'',
    userarea:["请选择"],
    sex_idx:0,
    job_idx:0,
    sex_data:[
      {
        id: 0,
        name: '请选择'
      },
      {
        id: 1,
        name: '男'
      },
      {
        id: 2,
        name: '女'
      },
    ],
    job_data: [
      {
        id: 0,
        name: '请选择'
      },
      {
        id: 1,
        name: '计算机/互联网/通信'
      },
      {
        id: 3,
        name: '公务员/事业单位'
      },
      {
        id: 4,
        name: '教师'
      },
      {
        id: 5,
        name: '医生'
      },
      {
        id: 6,
        name: '护士'
      },
      {
        id: 7,
        name: '教师'
      },
      {
        id: 8,
        name: '空乘人员'
      },
      {
        id: 9,
        name: '生产/工艺/制造'
      },
      {
        id: 10,
        name: '商业/服务业/个体经营'
      },
      {
        id: 11,
        name: '金融/银行/投资/保险'
      },
      {
        id: 12,
        name: '文化/广告/传媒'
      },
      {
        id: 13,
        name: '娱乐/艺术/表演'
      },
      {
        id: 14,
        name: '律师/法务'
      },
      {
        id: 15,
        name: '其它'
      }
    ],
    specificarea:null,
  },

  onLoad: function(options) {

    if(wx.getStorageSync('specificarea')) {
      this.setData({
        specificarea:wx.getStorageSync('specificarea')
      })
    }
      // wx.hideShareMenu();
      let userInfo = wx.getStorageSync('userInfo');
      this.setData({
        nickname: userInfo.nickname,
        headimg: userInfo.headimg
      });
  },
  onReady: function() {},
  onShow: function() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {},
  bind_nickname: function (e) {
    this.setData({
      nickname: e.detail.value
    })
  },
  bind_sex:function(e){
    this.data.sex_idx = e.detail.picker_idx;
  },
  bind_job: function (e) {
    this.data.job_idx = e.detail.picker_idx;
  },
  bind_userarea: function (e) {
    this.data.userarea = e.detail.region;
  },
  bind_birthday: function (e) {
    this.data.birthday = e.detail.picker_date;
  },
  bind_sumbit: function (e) {
    var that = this;
    let userInfo = wx.getStorageSync('userInfo');

    var re_param = {
      "area": this.data.specificarea,
      "memberId": userInfo["id"],

      "headimg": this.data['headimg'],
      "nickname": this.data['nickname'],
      "sex": this.data['sex_data'][this.data.sex_idx].name,
      "occupation": this.data['job_data'][this.data.job_idx].name,
      "birthday": this.data['birthday'],
      "userarea": this.data['userarea'].join(","),
    }
    fetch(`wx/member/${this.data.specificarea}/updMemberInfo`, 'POST', re_param).then(res=>{
        if(res) {
          that.data.cur_mid = data.id;
          if (data.fee > 0) {
            that.pay(data.fee);
          } else {
            //跳转
            wx.redirectTo({
              url: '/pages/detailsInfo/index?id=' + that.data.cur_mid,
            })
          }
        }
    })


  }
})
